// console.log('你看看这里是jsssss')
getXML.onclick = () => {
  const request = new XMLHttpRequest();
  request.open('GET', '/xml')
  request.onreadystatechange = () => {
    if (request.readyState === 4) {
      if (request.status >= 200 && request.status < 300) {
        // .requestXML直接获取到这个XMLdom节点
        const xmlDom1 = request.responseXML;
        const xmlDom = xmlDom1.getElementsByTagName('warning')[0]
        console.log('xml 内容：', xmlDom.textContent.trim())
        const xmlContent = document.createElement('div');
        xmlContent.textContent = `这里是xml文件的文本内容：${xmlDom.textContent.trim()}`;
        container.appendChild(xmlContent)
      }
    }
  }
  request.send();
}
let currentPage = 1;
getJson.onclick = () => {
  const request = new XMLHttpRequest();
  // console.log(`/page${currentPage}.json`)
  request.open('GET', `/page${currentPage}.json`)
  request.onreadystatechange = () => {
    if (request.readyState === 4) {
      if (request.status >=200 && request.status < 300) {
        const page1Data = request.response;
        const jsonArray  = JSON.parse(page1Data);
        jsonArray.forEach(item => {
          const newLiDom = document.createElement('li');
          newLiDom.textContent = `${item.name}: ${item.id}`
          contentDom.appendChild(newLiDom);
        });
        currentPage = currentPage +1;
      }
    }
  }
  request.send();
}
getCss.onclick = () => {
  const request = new XMLHttpRequest();
  request.open('GET', '/style.css')
  request.onreadystatechange = () => {
    if (request.readyState === 4) {
      // 下载操作已经完成DONE
      if (request.status >=200 && request.status < 300) {
        const styleEl = document.createElement('style')
        styleEl.innerHTML = request.response;
        document.head.appendChild(styleEl)
      } else {
        alert('加载失败')
      }
    }
  }
  request.onerror = () => {
    console.log('出错了')
  }
  request.send();
}

getJs.onclick = () => {
  const request = new XMLHttpRequest();
  request.open('GET', '/mymain.js')
  request.onload = () => {
    // console.log('成功到达了')
    const scriptEl =  document.createElement('script')
    scriptEl.innerHTML = request.response;
    // console.log(request.response, 23)
    container.appendChild(scriptEl)
  }
  request.onerror = () => {
    console.log('出错了')
  }
  request.send();
}

getHtml.onclick = () => {
  const request = new XMLHttpRequest();
  request.open('GET', '/myhtml.html')
  request.onload = () => {
    const htmlEl =  document.createElement('div')
    htmlEl.innerHTML = request.response;
    document.body.appendChild(htmlEl)
  }
  request.onerror = () => {
    console.log('出错了')
  }
  request.send();
}